/**
* 版权声明：厦门睿商网络科技有限公司 版权所有 违者必究
* 日    期：2020-02-17
*/
package com.rzico.account.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.rzico.annotation.IgnoreSwaggerParameter;
import com.rzico.basics.entity.Member;
import io.swagger.models.auth.In;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.*;
import io.swagger.annotations.ApiModelProperty;

/**
 * <pre>
 *   应收款数据库对象
 * </pre>
 * @author Rzico Boot
 * @version 1.0
 */
@Data
@JsonIgnoreProperties(value = {"handler"})
@JsonInclude(JsonInclude.Include.NON_NULL)
@Table(name = "wx_receivable")
public class Receivable{
    @ApiModelProperty(value = "")
    @Id
    protected Long id;

    @ApiModelProperty(value = "创建日期")
    protected java.util.Date createDate;

    @ApiModelProperty(value = "修改日期")
    protected java.util.Date modifyDate;

    @ApiModelProperty(value = "应收金额")
    protected java.math.BigDecimal amount;

    @ApiModelProperty(value = "已收金额")
    protected java.math.BigDecimal amountPaid;

    @ApiModelProperty(value = "应收水票")
    protected Integer quantity;

    @ApiModelProperty(value = "已收水票")
    protected Integer quantityPaid;

    @ApiModelProperty(value = "账款类型(0.应收款,1.应退款)")
    protected Integer type;

    @ApiModelProperty(value = "是否删除")
    protected Boolean deleted;

    @ApiModelProperty(value = "状态(0.待收款,1.部份收款,2.已完成)")
    protected Integer status;

    @ApiModelProperty(value = "会员")
    protected Long memberId;

    @ApiModelProperty(value = "")
    protected Long enterpriseId;

    @ApiModelProperty(value = "订单类型 {0:订单,1.出库,2.退货}")
    protected Integer orderType;

    @ApiModelProperty(value = "订单ID")
    protected Long orderId;

    @ApiModelProperty(value = "订单号")
    protected String orderSn;

    @ApiModelProperty(value = "所属部门")
    protected String officeId;

    @ApiModelProperty(value = "创建者")
    protected String createBy;

    @ApiModelProperty(value = "更新者")
    protected String modifyBy;

    @ApiModelProperty(value = "出入库单号")
    protected Long warehouseId;

    @ApiModelProperty(value = "支付插件")
    protected String paymentPluginId;

    @ApiModelProperty(value = "付款方式（中文名）")
    protected String paymentPluginName;

//    @ApiModelProperty(value = "当前收款金额")
//    @Column(insertable = false)
//    protected BigDecimal currentAmount;

    @ApiModelProperty(value = "可收款金额", hidden = true)
    public BigDecimal getAvailableAmount() {
        return getAmount().subtract(getAmountPaid());
    }

    @ApiModelProperty(value = "可收款水票", hidden = true)
    public BigDecimal calcAvailableQuantity() {
        return new BigDecimal(getQuantity()-getQuantityPaid());
    }

    @ApiModelProperty(value = "计算水票单价", hidden = true)
    public BigDecimal calcPaperPrice() {
        if (getQuantity()==0) {
            return BigDecimal.ZERO;
        }
        return getAmount().divide(new BigDecimal(getQuantity()),2,BigDecimal.ROUND_HALF_DOWN);
    }



    /**
     *  会员
     */
    @JsonIgnore
    @IgnoreSwaggerParameter
    protected Member member;


    public String getName() {
        Member member = getMember();
        if (member!=null) {
            return member.getName();
        } else {
            return null;
        }
    }

    public String getMobile() {
        Member member = getMember();
        if (member!=null) {
            return member.getMobile();
        } else {
            return null;
        }
    }
}
